package cn.wo.dao.impl;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;

import cn.wo.beans.Project;
import cn.wo.beans.Workorder;
import cn.wo.dao.IProjectDao;

public class ProjectDaoImpl implements IProjectDao {

	private SessionFactory sessionFactory;
	
	public List<Project> findAll() {
		Session session = sessionFactory.openSession();
		Criteria criteria = session.createCriteria(Project.class);
		return  criteria.list();
	}

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	public void addOrder(Workorder order) {
		Session session = sessionFactory.getCurrentSession();
		session.save(order);
		
	}

	public List<Workorder> findAllOrder() {
		Session session = sessionFactory.openSession();
		return session.createCriteria(Workorder.class).list();
	}

	public Project getProjectByPid(Serializable pid) {
		Session session = sessionFactory.openSession();
		return (Project) session.get(Project.class, pid);
	}

}
